@echo off
setlocal

set "SCRIPT_DIR=%~dp0"
pushd "%SCRIPT_DIR%.."

if not exist .venv (
  echo venv not found. Creating...
  call scripts\make_venv.bat || exit /b 1
)

call .venv\Scripts\activate.bat

REM Ensure required packages are installed (with CN mirror)
python -c "import PySimpleGUI, watchdog" >nul 2>nul
if errorlevel 1 (
  echo Installing required packages with Tsinghua mirror...
  pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple >nul
  python -m pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple || exit /b 1
  pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple || exit /b 1
)

python main.py

popd